﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Http;
using System.Web.Http;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Smo.Agent;
using System.Configuration;


namespace MMSA.HttpServices.Controllers
{
    public class SincronizarBasesController : ApiController
    {
        // GET: SincronizarBases
        /*public ActionResult Index()
        {
            return View();
        }*/

        // GET api/values
        public string Get()
        {
            string status = "";
            Server server = new Server(ConfigurationManager.AppSettings["instance"].ToString());
            try
            {

                server.ConnectionContext.LoginSecure = false;
                server.ConnectionContext.Login = ConfigurationManager.AppSettings["userName"].ToString();
                //"erp_movil";
                server.ConnectionContext.Password = ConfigurationManager.AppSettings["password"].ToString();
                server.ConnectionContext.Connect();
                Job job = server.JobServer.Jobs[ConfigurationManager.AppSettings["job"].ToString()];
                job.Start();
                status = "ok";
            }
            catch (Exception ex)
            {
                status = "fail";

            }
            finally
            {
                if (server.ConnectionContext.IsOpen)
                {
                    server.ConnectionContext.Disconnect();
                }
            }
            return status;
        }
		
    }
}